package br.com.rfqx.account;

import java.io.Serializable;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.validation.constraints.NotNull;

import lombok.Data;

@Data
@Entity
@DiscriminatorValue(value = "CUSTOMER")
public class Customer extends Account implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	@NotNull
	private String code;
	
	@Embedded
	@AttributeOverrides({ @AttributeOverride(name="address"
											, column = @Column(name="billto_address"))
						, @AttributeOverride(name="city"
								, column = @Column(name="billto_city"))
						, @AttributeOverride(name="country"
								, column = @Column(name="billto_country"))
						, @AttributeOverride(name="province"
								, column = @Column(name="billto_province"))
						, @AttributeOverride(name="state"
								, column = @Column(name="billto_state"))
						, @AttributeOverride(name="zipCode"
								, column = @Column(name="billto_zipcode"))

						, @AttributeOverride(name="addressType"
								, column = @Column(name="billto_addressType"))
	})
	private Address billto;
	
	@Embedded
	@AttributeOverrides({ @AttributeOverride(name="address"
											, column = @Column(name="shipto_address"))
						, @AttributeOverride(name="city"
								, column = @Column(name="shipto_city"))
						, @AttributeOverride(name="country"
								, column = @Column(name="shipto_country"))
						, @AttributeOverride(name="province"
								, column = @Column(name="shipto_province"))
						, @AttributeOverride(name="state"
								, column = @Column(name="shipto_state"))
						, @AttributeOverride(name="zipCode"
								, column = @Column(name="shipto_zipcode"))
						, @AttributeOverride(name="addressType"
								, column = @Column(name="shipto_addressType"))
	})
	private Address shipto;
		
	public Customer() {
		withBillto();
		withShipto();
	}
	

	public Customer(Long id, String name, String code) {
		super(id,name);
		this.code = code;
	}
	
	public Address withBillto() {
		if (billto == null) billto = new Address();
		billto.withAddressType(AddressType.BILLTO);
		return billto;
	}


	public Address withShipto() {
		if (shipto == null) shipto = new Address();
		shipto.withAddressType(AddressType.SHIPTO);
		return shipto;
	}




	

	
	
	
}
